home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#05 (Dec85-Jan86)
/
basic
/
icon game 1-13
/
Icon Match
next >
Wrap
Text File
|
1985-10-15
|
7KB
|
254 lines
'Icon Match Game
'By Dave Kelly
'MACTUTOR ©1985
'Main Program intialization
WINDOW CLOSE 1
DEFINT a-z 'set variables as type integer
Iconsize%=500
DIM length(12),Icon$(12),Iconput%(Iconsize%,12),r%(24),door(24)
FOR i= 0 TO 3:patt%(i)=&H55AA:NEXT i 'set up pattern
true=-1:false=0:opened=-1:closed=0:found=1:iconloaded=false
'set up menus
FOR i=3 TO 5: MENU i,0,0,"": NEXT i
MENU 1,0,1,"Icon Match"
MENU 1,1,0,"Start Game (Current Icons)"
MENU 1,2,1,"New Game (New Icons)"
MENU 1,3,0,"-"
MENU 1,4,1,"CREATE New Icons"
MENU 1,5,0,"-"
MENU 1,6,1,"Quit"
setmenu:ON MENU GOSUB Mcheck:MENU ON
endlessloop:IF iconloaded THEN MENU 1,1,1 ELSE MENU 1,1,0
GOTO endlessloop
Mcheck: 'check item for menu 1
menunum=MENU(0):IF menunum <>1 THEN MENU:RETURN
menuitem=MENU(1):MENU
ON menuitem GOSUB Startgame,Newgame,,Createicons,,Quit
RETURN
Newgame:
iconloaded=false
Startgame:
IF iconloaded=false THEN GOSUB Readicons
IF filename$="" THEN RETURN
MENU 1,1,0:MENU 1,2,0:MENU 1,4,0
numberfound=0:guesses=0
GOSUB Shuffle 'shuffle icons
WINDOW 1,,(2,40)-(510,275),3
MENU ON
FOR i=1 TO 24
door(i)=closed
NEXT i
GOSUB Play
WINDOW CLOSE 1
MENU 1,1,1:MENU 1,2,1:MENU 1,4,1
RETURN
Drawstatus: 'Draw the screen with current status
i=1
x1=30:y1=30:x2=50+x1:y2=50+y1
WHILE i<=24
rect%(0)=y1:rect%(1)=x1:rect%(2)=y2:rect%(3)=x2
IF door(i)=found THEN ERASERECT(VARPTR(rect%(0))):GOTO skip
IF door(i)=closed THEN CALL FILLRECT(VARPTR(rect%(0)),VARPTR(patt%(0))):CALL FRAMERECT(VARPTR(rect%(0)))
IF door(i)=opened THEN ERASERECT(VARPTR(rect%(0))):PUT(x1,y1)-(x2-1,y2-1),Iconput%(0,r%(i))
skip:x1=x1+55:x2=x2+55:i=i+1
IF i=9 THEN x1=30:y1=y2+5:x2=50+x1:y2=50+y1
IF i=17 THEN x1=30:y1=y2+5:x2=50+x1:y2=50+y1
WEND
RETURN
Play:
FOR i=1 TO 24
IF door(i)=opened THEN door(i)=closed
NEXT i
mousee=MOUSE(0)
GOSUB Drawstatus
Open1stdoor:
mousee=MOUSE(0):IF mousee=0 THEN Open1stdoor
GOSUB finddoor
IF doornum=0 OR door(doornum)=found THEN Open1stdoor
door(doornum)=opened:doorA=doornum
GOSUB Drawstatus
mousee=MOUSE(0)
Open2nddoor:
mousee=MOUSE(0):IF mousee=0 THEN Open2nddoor
GOSUB finddoor
IF doornum=0 OR door(doornum)=found OR doornum=doorA THEN Open2nddoor
door(doornum)=opened:doorB=doornum
GOSUB Drawstatus
IF r%(doorA)=r%(doorB) THEN door(doorA)=found:door(doorB)=found:numberfound=numberfound+1
guesses=guesses+1:CALL TEXTFONT(0):CALL MOVETO(100,210):PRINT "Number of Guesses:";guesses;" Number found:";numberfound
FOR i=1 TO 2000:NEXT i
IF numberfound<>12 THEN Play
RETURN
finddoor:
doornum=0:row1=0:row2=8:row3=16
xpos=MOUSE(1):ypos=MOUSE(2)
IF xpos>465 OR xpos <30 OR ypos <30 OR ypos >190 THEN RETURN
rows:'Find selected row
IF ypos>=30 AND ypos <=80 THEN doornum=doornum+row1:GOTO cols
IF ypos>=85 AND ypos <=135 THEN doornum=doornum+row2:GOTO cols
IF ypos>=140 AND ypos <=190 THEN doornum=doornum+row3:GOTO cols
RETURN
cols:'Find selected column
IF xpos>=30 AND xpos<=80 THEN doornum=doornum+1:RETURN
IF xpos>=85 AND xpos<=135 THEN doornum=doornum+2:RETURN
IF xpos>=140 AND xpos<=190 THEN doornum=doornum+3:RETURN
IF xpos>=195 AND xpos<=245 THEN doornum=doornum+4:RETURN
IF xpos>=250 AND xpos<=300 THEN doornum=doornum+5:RETURN
IF xpos>=305 AND xpos<=355 THEN doornum=doornum+6:RETURN
IF xpos>=360 AND xpos<=410 THEN doornum=doornum+7:RETURN
IF xpos>=415 AND xpos<=465 THEN doornum=doornum+8:RETURN
doornum=0
RETURN
Shuffle:
WINDOW 2,,(150,100)-(350,150),-2
TEXTFONT(0):LOCATE 1,3:PRINT "Please wait...."
LOCATE 2,3:PRINT"Now shuffling icons."
RANDOMIZE TIMER
r%(1)=1:r%(2)=2:r%(3)=3:r%(4)=4:r%(5)=5:r%(6)=6
r%(7)=7:r%(8)=8:r%(9)=9:r%(10)=10:r%(11)=11:r%(12)=12
r%(13)=1:r%(14)=2:r%(15)=3:r%(16)=4:r%(17)=5:r%(18)=6
r%(19)=7:r%(20)=8:r%(21)=9:r%(22)=10:r%(23)=11:r%(24)=12
mixstart=1:mixend=12:GOSUB mixup
mixstart=13:mixend=24:GOSUB mixup
FOR i=1 TO 12:SWAP r%(i),r%(i+6):NEXT i
WINDOW CLOSE 2
RETURN
mixup:
FOR i = mixstart TO mixend
getnewrnd:
r%(i)=INT(RND*12.4):IF r%(i)= 0 THEN getnewrnd
getanother=0
FOR j=mixstart TO i-1
IF r(i)=r(j) THEN getanother=1
NEXT j
IF getanother=1 THEN GOTO getnewrnd
NEXT i
RETURN
Quit:
CLS:MENU RESET:END
Createicons:
'Match Game Icon Creator
'
'Make your Icon in MacDraw or MacPaint
'then copy to scrapbook. This program will
'read your Icon from the clipboard.
'CAUTION: click once on the output window before copying
'if you don't want to close scrapbook for
'multiple clips. Use Add to add an icon to the file.
'Pictures of any size may be used. They will be scaled
'when clipped from the clipboard.
MENU 1,0,0
MENU 3,0,1,"Add Match Icons"
MENU 3,1,1,"Display Current Icons"
MENU 3,2,1,"Add an Icon"
MENU 3,3,0,"-"
MENU 3,4,1,"Save Current Icons to disk"
MENU 3,5,1,"Read Current Icons from disk"
MENU 3,6,0,"-"
MENU 3,7,1,"Clear Icons"
MENU 3,8,1,"Return to Match Game"
WINDOW 1,,(2,40)-(510,275),3
ON MENU GOSUB Checkmenu:MENU ON
Infiniteloop:
IF iconloaded=false THEN MENU 3,4,0:MENU 3,2,1
IF iconloaded=true THEN MENU 3,4,1:MENU 3,2,0
GOTO Infiniteloop
Checkmenu: 'check items FOR MENU 3
menunum=MENU(0): IF menunum<>3 THEN RETURN
menuitem=MENU(1): MENU
ON menuitem GOSUB Displayicons,Add,,SaveALL,Readicons,,Startover,Quitcreate
RETURN
Startover: 'Clear all icons
CLS:count=0
iconloaded=false
RETURN
Add: 'add an icon to the file
count=count+1
GOSUB CopyfromClip
GOSUB Displayicons
IF count=12 THEN iconloaded=true
RETURN
CopyfromClip: 'copy picture from clipboard
OPEN "CLIP:PICTURE" FOR INPUT AS 1
length(count)=LOF(1)
Icon$(count)=INPUT$(length(count),1)
CLOSE 1
RETURN
Quitcreate: 'quit icon creation
WINDOW CLOSE 1
MENU 3,0,0,""
MENU 1,0,1
RETURN setmenu
SaveALL:
filename$=FILES$(0,"Enter Icon Filename:")
IF filename$="" THEN RETURN
WINDOW 2,,(150,100)-(350,150),-2
TEXTFONT(0):LOCATE 1,3:PRINT "Please wait...."
LOCATE 2,3:PRINT"Now saving icons."
OPEN filename$ FOR OUTPUT AS 1
FOR count=1 TO 12
FOR size= 0 TO Iconsize%
WRITE #1,Iconput%(size,count)
NEXT size
NEXT count
count=12
CLOSE 1
NAME filename$ AS filename$,"BICN"
WINDOW CLOSE 2
RETURN
Readicons:
filename$=FILES$(1,"BICN")
IF filename$="" THEN RETURN
WINDOW 2,,(150,100)-(350,150),-2
TEXTFONT(0):LOCATE 1,3:PRINT "Please wait...."
LOCATE 2,3:PRINT"Now loading icons."
OPEN filename$ FOR INPUT AS 1
x=LOF(1)
IF x=0 THEN LOCATE ,10:PRINT "No Icons Exist":BEEP:CLOSE 1:RETURN
FOR count=1 TO 12
FOR size=0 TO Iconsize%
INPUT #1,Iconput%(size,count)
NEXT size
NEXT count
CLOSE 1
count=12
iconloaded=true
WINDOW CLOSE 2
RETURN
Displayicons:
CLS:TEXTFONT(0)
x1=30:y1=30:x2=50+x1:y2=50+y1
i=1
WHILE i<= count
IF iconloaded=true THEN PUT(x1,y1)-(x2,y2),Iconput%(0,i) ELSE PICTURE (x1,y1)-(x2,y2),Icon$(i):GET (x1,y1)-(x2,y2),Iconput%(0,i)
MOVETO (x2-x1)/2+x1,y2+20:PRINT i
x1=x1+70:x2=x2+70:i=i+1
IF i=7 THEN x1=30:y1=120:x2=50+x1:y2=50+y1
WEND
RETURN